CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


  
'set the desired I2C pins here.
SDA     = 0
SCL     = 1

EE_DEVICE_ADDR  = $A0

PROPELLER_SDA   = 29
PROPELLER_SCL   = 28

obj

  i2c   :       "new_i2c"  
  d     :       "Parallax Serial Terminal"
  
pub go | i, in

  i2c.StartI2C(SDA, SCL)
  'i2c.StartI2C(PROPELLER_SDA, PROPELLER_SCL)

  d.start(115_200)

  PauseMS(5000)
  d.clear

  'PrintRaw
  PrintChartStyle

pub PrintRaw | i

  repeat i from $0000 to $8000-1
  
    d.char(readByte(i))    '<----- transmits the raw value to the terminal

    'd.char(" ")                'add space
    
    'd.char(13)                 'add newline

pub PrintChartStyle | i

  d.str(string("Dumping EEPROM Contents:", 13))

  repeat ($8000/16)             '16 cols in a line
    
    d.str(string("0x"))
    d.hex(i, 8)
    d.char(":")
    d.char(" ")

    repeat 16
      d.hex(readByte(i++), 2)
      d.char(" ")
      'PauseMS(50)

    d.char(13)
    
    
    'd.hex(i2c.readByte(i), 2)   '<----- Prints the ASCII equivalent of the hex value in the EEPROM.



  d.str(string("============= Done =============="))
    
pub PauseMS(Duration)
''  Pause execution for 'duration' milliseconds.
''  This routine is based on the set clock frequency.
''  
''  params:  Duration = number of milliseconds to delay                                                                                               
''  return:  none

  waitcnt((((clkfreq / 1_000) * Duration - 3932) #> 381) + cnt)  
    
pub readByte(addr) : rxByte

  i2c.SendStart
  i2c.TxByte(EE_DEVICE_ADDR & !$01) 'Slave Address + Write Command
  i2c.TxByte((addr>>8) & $FF)       'Send high byte of addy first
  i2c.TxByte(addr & $FF)            'Send low byte of the address second
  i2c.SendStart

  i2c.TxByte(EE_DEVICE_ADDR | $01)  'Slave Address + Read Command
  rxByte := i2c.RxByte(i2c#NAK)         'Read it out of eeprom
  i2c.SendStop  
  